package xuhaijia.lanou3g.autohome.recommend.bulletin;
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                   \\`.
//        .'//            为什么坚持  想一想当初             \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-.  \\`.
//    .'//.-"                 `-.  |  .-'                 "-. \\`.
//  .'//______.============-..   \ | /   ..-============._______\\`.
//.'//____________________________\|/_____________________________\\`.
// 
//                             

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import xuhaijia.lanou3g.autohome.R;
import xuhaijia.lanou3g.autohome.base.NetTool;
import xuhaijia.lanou3g.autohome.forum.hotinvitation.HotInvitationBean;

/**
 * Created by 7 on 16/8/18.
 */
public class BulletinAdapter extends BaseAdapter {
    private Context context;
    private BulletinBean bulletinBean;

    public BulletinAdapter(Context context) {
        this.context = context;
    }

    public void setBulletinBean(BulletinBean bulletinBean) {
        this.bulletinBean = bulletinBean;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (bulletinBean == null) {
            return 0;
        }
        return bulletinBean.getResult().getList().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        NetTool mNetTool = new NetTool();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_bulletin, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        BulletinBean.ResultBean.ListBean listBean =
                bulletinBean.getResult().getList().get(position);
        viewHolder.titleTv.setText(listBean.getTitle());
        viewHolder.historyTy.setText(listBean.getReviewcount() + "人浏览");
        viewHolder.dateTv.setText(listBean.getCreatetime());
        mNetTool.getImage(listBean.getBgimage(), viewHolder.iv);
        if (listBean.getState() == 2) {
            viewHolder.stateTv.setText("播报结束");
            viewHolder.stateTv.setTextColor(0xffcccccc);
            viewHolder.stateTv.setBackgroundResource(R.drawable.gray_textview);
        } else if (listBean.getState() == 1) {
            viewHolder.stateTv.setText("播报中");
            viewHolder.stateTv.setTextColor(0xff1B3FE2);
            viewHolder.stateTv.setBackgroundResource(R.drawable.blue_textview);
        } else if (listBean.getState() == 0) {
            viewHolder.stateTv.setText("即将播报");
            viewHolder.stateTv.setTextColor(0xff31a12f);
            viewHolder.stateTv.setBackgroundResource(R.drawable.green_textview);
        } else {
            viewHolder.stateTv.setVisibility(View.GONE);
        }


        return convertView;
    }

    private class ViewHolder {
        TextView titleTv;
        TextView historyTy;
        TextView dateTv;
        ImageView iv;
        TextView stateTv;

        public ViewHolder(View view) {
            titleTv = (TextView) view.findViewById(R.id.item_bulletin_title);
            historyTy = (TextView) view.findViewById(R.id.item_bulletin_history);
            dateTv = (TextView) view.findViewById(R.id.item_bulletin_date);
            iv = (ImageView) view.findViewById(R.id.item_bulletin_iv);
            stateTv = (TextView) view.findViewById(R.id.item_bulletin_state);
        }
    }
}
